#!/usr/bin/env escript

main(_) ->
	process([1, 3, 9, 8, 2, 3, 1, 8]).
	
do_work(Caller, X) ->
	io:format("working on ~p...~n", [X]),
	Caller ! {self(), X * 2}.
	
process_response([]) -> void;
process_response([Pid|T]) ->
	receive
		{Pid, Val} -> io:format("Received ~p~n", [Val]),
		process_response(T)
	end.
	
process(L) ->
	Caller = self(),
	Pids = lists:map(fun(E) -> spawn(fun() -> do_work(Caller, E) end) end, L),
	process_response(Pids).